package com.zygh.policeasset.service;

import cn.hutool.core.date.DateUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zygh.policeasset.mapper.AuditFlowMapper;
import com.zygh.policeasset.mapper.UnitInformationMapper;
import com.zygh.policeasset.mapper.UploadFileMapper;
import com.zygh.policeasset.pojo.Project;
import com.zygh.policeasset.pojo.TableType;
import com.zygh.policeasset.pojo.UnitInformation;
import com.zygh.policeasset.pojo.UploadFile;
import com.zygh.policeasset.utils.AuditUtil;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
/* loaded from: police-asset-2.0-0.0.1-SNAPSHOT.jar:BOOT-INF/classes/com/zygh/policeasset/service/UnitInformationService.class */
public class UnitInformationService {
    @Autowired
    UnitInformationMapper unitInformationMapper;
    @Autowired
    UploadFileMapper uploadFileMapper;
    @Autowired
    AuditFlowMapper auditFlowMapper;
    @Autowired
    AuditFlowService auditFlowService;

    public PageInfo findByProject(String projectNo, String name, Integer status, int pageNum,
                                  int pageSize, String unitNature, Integer userId) {
        PageHelper.startPage(pageNum, pageSize);
        return new PageInfo<>(this.unitInformationMapper.findByProject(projectNo, name, status, unitNature, userId));
    }

    public UnitInformation findById(Integer id) {
        return this.unitInformationMapper.findById(id);
    }

    public List<UnitInformation> findByProjectNoPage(String projectNo) {
        return this.unitInformationMapper.findByProject(projectNo, "", 0, "", null);
    }

    public List<Project> getAdd() {
        return this.unitInformationMapper.getAdd();
    }

    public Integer add(UnitInformation unitInformation) {
        int unitInformationId = 0;
        String now = DateUtil.now();
        String flowNo = AuditUtil.getFlowNo(now);
        unitInformation.setFlowNo(flowNo);
        try {
            this.unitInformationMapper.add(unitInformation);
            unitInformationId = unitInformation.getId();
            this.auditFlowService.add(unitInformation.getUserId(), flowNo, now, TableType.UNITINFORMATION.getName(), TableType.UNITINFORMATION.getType(), unitInformation.getProjectNo(), null);
            for (UploadFile uploadFile : unitInformation.getUploadFileList()) {
                uploadFile.setProjectId(unitInformationId);
                uploadFile.setProjectName("unit_information");
                uploadFile.setCreateDate(DateUtil.now());
                this.uploadFileMapper.add(uploadFile);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Integer.valueOf(unitInformationId);
    }

    public Integer update(UnitInformation params) {
        return this.unitInformationMapper.update(params);
    }

    public Integer remove(int id) {
        int res = 0;
        try {
            res = this.unitInformationMapper.remove(id).intValue();
            this.uploadFileMapper.delete(id, "unit_information");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Integer.valueOf(res);
    }

    public Integer updateByid(@Param("id") Integer id, @Param("status") Integer status) {
        return this.unitInformationMapper.updateByid(id, status);
    }
}